package com.turing.pre.processor.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.turing.common.response.ResponseVO;
import com.turing.common.util.ResponseUtil;
import com.turing.pre.processor.domain.PreProcessorTask;
import com.turing.pre.processor.enums.AnalysisStatusEnum;
import com.turing.pre.processor.enums.PreProcessorStatusEnum;
import com.turing.pre.processor.file.processor.Document4jApp;
import com.turing.pre.processor.file.processor.FileToPdf;
import com.turing.pre.processor.service.PreProcessorTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("preprocessor")
public class preprocessorController {

    @Autowired
    private PreProcessorTaskService preProcessorTaskService;

    @PostMapping("removeTasks")
    public ResponseVO<Object> removeTasks(@RequestBody List<String> taskSns){

        boolean remove = preProcessorTaskService.remove(new LambdaQueryWrapper<PreProcessorTask>().in(PreProcessorTask::getParentTaskSn, taskSns));
        return ResponseUtil.success(remove);

    }

    @PostMapping("taskFailed")
    public ResponseVO<Object> taskFailed(@RequestParam("parentTaskSn") String parentTaskSn){

        boolean updated = preProcessorTaskService.lambdaUpdate().eq(PreProcessorTask::getParentTaskSn,parentTaskSn)
                .set(PreProcessorTask::getPreProcessorStatus, PreProcessorStatusEnum.ERROR.getCode())
                .set(PreProcessorTask::getAnalysisStatus, AnalysisStatusEnum.ERROR.getCode()).update();
        return ResponseUtil.success(updated);

    }

    @PostMapping("/testMethod")
    public String TestMethod(@RequestParam("inputFilePath")String inputFilePath,@RequestParam("pdfFilePath")String pdfFilePath){
//        String inputFilePath = "C:\\Users\\zhiqiang\\Desktop\\项目\\南京银行\\000847_中融货币市场基金2021年第三季度报告(1).doc";
//        String pdfFilePath = "C:\\Users\\zhiqiang\\Desktop\\项目\\南京银行\\000847_中融货币市场基金2021年第三季度报告(1)_document4j3.pdf";
//        Document4jApp.word2PDF(inputFilePath,pdfFilePath);
        try {
            FileToPdf.fileToPdf(inputFilePath,pdfFilePath,"doc");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "success";
    }

    public static void main(String[] args) {
        try {
            String inputFilePath = "C:\\Users\\zhiqiang\\Desktop\\项目\\南京银行\\000847_中融货币市场基金2021年第三季度报告(1).doc";
            String pdfFilePath = "C:\\Users\\zhiqiang\\Desktop\\项目\\南京银行\\000847_中融货币市场基金2021年第三季度报告(1)_111.pdf";
            FileToPdf.fileToPdf(inputFilePath,pdfFilePath,"doc");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
